import React, { Component } from 'react'
import ProceDures from './Mask'
import Style from './index.scss'

export default class ProceDuresList extends Component {
	constructor(props) {
		 super(props);
		 
		 let selectIndex = this.props.index > -1 ? (this.props.index*1) : -1;
		 this.state = {
		 	selectIndex: selectIndex
		 }
	}

	//返回的优惠券数据
	getData(data){
		//选中的优惠券
		this.setState({
			selectIndex: data.index
		})

		if(this.props.onClick){
			this.props.onClick(data); //传递给父组件
		}		
	}

	render() {
		console.log(this.state.selectIndex, "this.state.selectIndex")
		return (
			<div className={Style.couponList}>
				{
					this.props.list.length !==0 ? this.props.list.map((item, i) =>
						<ProceDures key={i} index={i} {...item} Selected={this.state.selectIndex === i ? true : false } onClick={(i, amount) => this.getData(i, amount)}/>
					) : ''
				}
			</div>
		)
	}
}

ProceDuresList.defaultProps = {
	list : [
		{
			value: 0,
			label: '车辆违章确认',
		}
	]
}